package com.oss.robot;

import java.util.List;

import com.oss.model.Link;
import com.oss.model.Project;
import com.oss.model.Topic;
import com.oss.service.system.CacheService;

/**
 * 统计Project和Topic上的Link的数量
 * 
 * @author xueqiang.mi
 * @since 2010-8-15
 */
public class StatRobot extends BaseRobot {

	public void statQuantity(long pageIndex, long pageSize) {
		List<Project> prjs = CacheService.getPrjs();
		for (Project prj : prjs) {
			List<Link> lnks = lnkService.getLnksByPrj("user", prj.getId(),
					pageIndex, pageSize);
			prj.setLinkQuantity(Long.valueOf(lnks.size()));
			prjService.save(prj);
		}
		List<Topic> topics = CacheService.getTopics();
		for (Topic topic : topics) {
			List<Link> lnks = lnkService.getLnksByTopic(topic.getId(),
					pageIndex, pageSize);
			topic.setLinkQuantity(Long.valueOf(lnks.size()));
			topicService.save(topic);
		}
	}

}
